package com.bkitclub.mobiledevcamp.horseword.util;

import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class ResourceManager {
	private static final String hugeResource = "huge/";
	private static final String largeResource = "large/";
	private ResourceManager(){
		int type = Utils.getResourceType();
		switch (type) {
		case Utils.RESOURCE_TYPE_HUGE:
			resourceSize = hugeResource;
			break;
		case Utils.RESOURCE_TYPE_LARGE:
			resourceSize = largeResource;
			break;
		case Utils.RESOURCE_TYPE_MEDIUM:
			resourceSize = largeResource;
			scaleSize = 480.0 / 800;
			break;
		case Utils.RESOURCE_TYPE_SMALL:
			resourceSize = largeResource;
			scaleSize = 320.0 / 800;
			break;
		default:
			break;
		}
	}
	private double scaleSize = 1;
	private String resourceSize;
	private static ResourceManager instance;
	public static ResourceManager getInstance(){
		if(instance == null)
			instance = new ResourceManager();
		return instance;
	}
	public Bitmap getImage(Context context,String resource){
		Bitmap result = null;
		try {
			InputStream fis = context.getAssets().open(resourceSize + resource);
			result = BitmapFactory.decodeStream(fis);
			if(scaleSize != 1){
				result = Bitmap.createScaledBitmap(result, (int)(result.getWidth() * scaleSize), (int) (result.getHeight() * scaleSize), false);
			}
			return result;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return null;
		}
		
	}
}
